Ext.namespace('TaxonTagger');
TaxonTagger.FileSettings = function(config){

	this.prop = new TaxonTagger.Properties({
			autoHeight: true
		,	style: 'border-top: solid thin;'
	});

	Ext.apply(this, config, {
			name: 'delimiterSetting'	
		,	defaults: {
				border: false
			}
		,	items: [{
					xtype: 'fieldset'                        
				,	defaultType: 'radio'
				,	ref: 'fileSettingOptions'
				,	defaults: {
							handler: this.changeProp
						,	scope: this
					}
				,	items: [{
							fieldLabel: this.txtFieldSetting
						,	itemId: 'radio-csv'
						,	ref: 'csv'
						,	boxLabel: this.txtFieldRadioCsv
						,	name: 'format'
						,	inputValue: 'csv'
					}, {
							fieldLabel: ''
						,	itemId: 'radio-tab'
						,	ref: 'tab'
						,	labelSeparator: ''
						,	boxLabel: this.txtFieldRadioTab
						,	name: 'format'
						,	inputValue: 'tab'
					}, {
							fieldLabel: ''
						,	itemId: 'radio-custom'
						,	ref: 'custom'
						,	labelSeparator: ''
						,	boxLabel: this.txtFieldRadioCustom
						,	name: 'format'
						,	inputValue: 'custom'
					}]
				,	listeners: {
							change: this.changeProp
						,	scope: this
					}
			}, this.prop
	    ]
		,	listeners: {
				render: function() {
					this.fileSettingOptions.getComponent('radio-csv').setValue(Config.delimiter.radioVal);
					this.fileSettingOptions.fireEvent('change', this.fileSettingOptions.getComponent('radio-csv'), true );
					this.loadLocalStroage();
				}
			}
	});
	
	TaxonTagger.FileSettings.superclass.constructor.call(this, config);

}

Ext.extend(TaxonTagger.FileSettings, Ext.form.FormPanel, {

		changeProp: function( obj, state ) {
			if (!state) {
				return;
			}
		
			switch( obj.inputValue ) {
		    case 'csv':
					var task = new Ext.util.DelayedTask(function(){
						this.prop.setCsv();
					}, this);
					task.delay(300); 
					break;

		    case 'tab':
					this.prop.setTab();
					break;
		        
		    default:
					this.prop.setCustom();
					break;
			}
		}

	,	loadLocalStroage: function(){
			var t = this.fileSettingOptions;
			var tConfig = Ext.decode(localStorage.getItem("settings")) || Config;
			if (tConfig["delimiter"]["csvStorage"]) {
				t.csv.setValue(true);
				this.prop.setCsv();
			} else {
				if (tConfig["delimiter"]["tabStorage"]) {
					t.tab.setValue(true);
					this.prop.setTab();
				} else {
					t.custom.setValue(true);
					this.prop.setCustom();
				}
			}
		}

});